﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
using GameEditor.View.Components;
using GameEngine.Clients.Silverlight.View.Components;

namespace SilverlightClientEditor.View.Components
{
    public partial class ViewEditorUC : UserControl, IViewEditorMenuView<int>
    {
        public event Action<string, string,object> OnAddShapeClick;
        public event Action<string, string> OnRemoveShapeClick;
        public event Action<string> OnCreateItemClick;
        //TODO public event Action<string, string> OnMoveShapeClick;

        public ViewEditorUC()
        {
            InitializeComponent();
            //addShapeComboBox.Items.Add("Cube");
            //addShapeComboBox.Items.Add("Elipse");
            //addShapeComboBox.Items.Add("Triangle");
            //addShapeComboBox.Items.Add("Image");
            //addShapeComboBox.SelectedIndex = 3;
        }

        public void Initialize(WorldUC world)
        {
            MapContainer.Children.Clear();
            MapContainer.Children.Add(world);
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //string buttonName = ((Button)sender).Name;
            //if (sender.Equals(addShapeButton))
            //{
            //    switch (addShapeComboBox.SelectedItem as string) {
            //        case "Image":
            //            OpenFileDialog dialog = new OpenFileDialog();
            //            dialog.Filter = "Image Files (*.jpg)|*.jpg";
            //            dialog.Multiselect = false;
            //            bool? rslt = dialog.ShowDialog();
            //            if (rslt.HasValue && rslt.Value) {
            //                 if (OnAddShapeClick != null)
            //                    OnAddShapeClick(
            //                            nameTextBox.Text, 
            //                            "LoadImage",
            //                            dialog.File
            //                            );
            //            }
            //            break;
            //        default:
            //            if (OnAddShapeClick != null)
            //                OnAddShapeClick(
            //                        nameTextBox.Text,
            //                        addShapeComboBox.SelectedItem as string,
            //                        ""
            //                        );
            //            break;
            //    }
            //}
            //else if (sender.Equals(removeShapeButton))
            //{
            //    if (OnRemoveShapeClick != null)
            //        OnRemoveShapeClick(nameTextBox.Text, shapeListBox.SelectedItem as string);
            //}
            //else if (sender.Equals(createButton))
            //{
            //    if (OnCreateItemClick != null)
            //        OnCreateItemClick(nameTextBox.Text);
                
            //}
        }

        public void AddShapeToList(string shape)
        {
            shapeListBox.Items.Add(shape);
        }

        public void RemoveShapeFromList(string shape)
        {
            shapeListBox.Items.Remove(shape);
        }

        public void RemoveAllShapes()
        {
            shapeListBox.Items.Clear();
        }

        public event Action OnNewClick;

        public event Action<string> OnCreateClick;

        public event Action<string> OnEditClick;

        public event Action<string> OnRemoveClick;

        public event Action<string> OnViewClick;

        public void RemoveAllShapesFromList()
        {
            throw new NotImplementedException();
        }

        public event GameEngine.View.Components.OnButtonClickHandler<IViewEditorMenuViewConstants.ButtonTags> OnExternalActionButtonClick;
    }
}
